import { IsNotEmpty, IsString } from 'class-validator';
import { Comment } from '../entities/comment.entity';
import { User } from 'src/entities/user.entity';
import { UserResponseDto } from './user.dto';

export class CreateCommentDto {
  @IsNotEmpty({ message: '评论内容不能为空' })
  @IsString()
  content: string;

  @IsNotEmpty({ message: '文章ID不能为空' })
  articleId: number;
}

export class CommentResponseDto {
  id: number;
  content: string;
  createdAt: Date;
  updatedAt: Date;
  author: UserResponseDto;
  articleId: number;
  isActive: number; // 添加isActive字段
  artinfo: { // 添加文章信息对象
    id: number;
    title: string;
  };

  constructor(comment: Comment, user: UserResponseDto, articleTitle?: string) {
    this.id = comment.id;
    this.content = comment.content;
    this.createdAt = comment.createdAt;
    this.updatedAt = comment.updatedAt;
    this.author = user;
    this.articleId = comment.articleId || 0;
    this.isActive = comment.isActive !== undefined ? comment.isActive : 1; // 默认为1（正常状态）
    this.artinfo = {
      id: comment.articleId || 0,
      title: articleTitle || '未知文章'
    };
  }
}